package com.java.thread;

/**
 * @Author hyx
 * @Description TODO
 * @Date 2024/3/4 10:59
 * @Version 1.0
 */
public class Ticket implements Runnable{


    private int num;

    public Ticket(int num) {
        this.num = num;
    }

    @Override
    public void run() {

        while (true){
            if(num >0 ){

                //体现线程安全问题  让线程停10ms
                try {
                    Thread.sleep(10);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName()+"sale ticket "+num--);
            }
        }
    }
}
